//
//  CDColumnSubscriptionCell.m
//  栏目中心Demo
//
//  Created by liaoxingchi on 16/9/24.
//  Copyright © 2016年 liaoxingchi. All rights reserved.
//

#import "CDColumnSubscriptionCell.h"
#import "Masonry.h"

@interface CDColumnSubscriptionCell ()

@property (nonatomic, weak) UIView *detailView;
@property (nonatomic, weak) UIImageView *iconView;
@property (nonatomic, weak) UILabel *headerLabel;
@property (nonatomic, weak) UILabel *contentLabel;
@property (nonatomic, weak) UILabel *subscribeLabel;
@property (nonatomic, weak) UIButton *subscribeBtn;
@end

@implementation CDColumnSubscriptionCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self setupUI];
    }
    return self;
}

- (void)awakeFromNib {
    
}
// 初始化UI
- (void)setupUI {
    self.backgroundColor = [UIColor darkGrayColor];
    // 创建控件
    UIView *detailView = [[UIView alloc] init];
    detailView.backgroundColor = [UIColor whiteColor];
    //图片
    UIImageView *iconView = [[UIImageView alloc] init];
    iconView.image = [UIImage imageNamed:@"cao"];
    [detailView addSubview:iconView];
    // 标题
    UILabel *headerLabel = [[UILabel alloc] init];
    headerLabel.text = @"德玛西亚";
    headerLabel.font = [UIFont systemFontOfSize:16];
    headerLabel.textColor = [UIColor blackColor];
    [detailView addSubview:headerLabel];
    
    //内容label
    UILabel *contentLabel = [[UILabel alloc] init];
    contentLabel.text = @"人在塔在 ";
    contentLabel.font = [UIFont systemFontOfSize:14];
    contentLabel.textColor = [UIColor darkGrayColor];
    contentLabel.numberOfLines = 2;
    [detailView addSubview:contentLabel];
    //订阅
    UILabel *subscribeLabel = [[UILabel alloc] init];
    subscribeLabel.textColor = [UIColor lightGrayColor];
    subscribeLabel.text = @"闻道者,朝生夕死;问道者,今夕何求";
    subscribeLabel.font = [UIFont systemFontOfSize:12];
    [detailView addSubview:subscribeLabel];
    //订阅按钮
    UIButton *subscribeBtn = [[UIButton alloc] init];
    [subscribeBtn setImage:[UIImage imageNamed:@"subscribe"] forState:UIControlStateNormal];
    [subscribeBtn setImage:[UIImage imageNamed:@"subscribed"] forState:UIControlStateNormal];
    [subscribeBtn addTarget:self action:@selector(subscribeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [detailView addSubview:subscribeBtn];
    
    [self.contentView addSubview:detailView];
    
    
    //布局
    [detailView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(1.5);
        make.bottom.equalTo(self.contentView).mas_offset(-1.5);
        make.left.equalTo(self.contentView).mas_offset(3);
        make.right.equalTo(self.contentView).mas_offset(-3);
    }];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(detailView).mas_offset(13);
        make.bottom.equalTo(detailView).mas_offset(-13);
        make.width.height.offset(89);
    }];
    [headerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(iconView);
        make.left.equalTo(iconView.mas_right).mas_offset(10);
    }];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(headerLabel);
        make.top.equalTo(headerLabel.mas_bottom).mas_offset(8);
    }];
    [subscribeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(iconView);
        make.leading.equalTo(contentLabel);
    }];
    [subscribeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(detailView);
        make.right.equalTo(detailView).mas_offset(-15);
        make.width.height.offset(35);
    }];
    
    self.detailView = detailView;
    self.iconView = iconView;
    self.headerLabel = headerLabel;
    self.contentLabel = contentLabel;
    self.subscribeLabel = subscribeLabel;
    self.subscribeBtn = subscribeBtn;
    
}

- (void)subscribeBtnClick:(UIButton *)sender {
    NSLog(@"😘");
    
//    [sender setImage:[UIImage imageNamed:@"subscribed"] forState:UIControlStateNormal];
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
